﻿using System;
using System.Data;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Zvezda.FSO2.DB;
using Zvezda.FSO2.DB.DataSetFSOTableAdapters;


namespace FSO
{
    public partial class FormContract : Form, InterfaceObjDeleteableForm
    {
        //Объекты связанные с договором в рамках части по исходящем счетам
        private RadListDataItem[] _refObjects = {
                                                        new RadListDataItem("Исходящий счет"){Value = ObjctTypeEnum.INVOICE_OUT},
                                                        new RadListDataItem("Входящий платеж"){Value = ObjctTypeEnum.PAYMENT_IN},
                                                        new RadListDataItem("Календарный план"){Value = ObjctTypeEnum.CALENDAR_PLAN},
                                                        new RadListDataItem("Простокол согласования цены"){Value = ObjctTypeEnum.COST_PROTOCOL},
                                                        new RadListDataItem("Служебная записка"){Value = ObjctTypeEnum.DIRECT},
                                                        new RadListDataItem("Цеховая накладная"){Value = ObjctTypeEnum.GUILD_BILL},
                                                        new RadListDataItem("Счет фактура"){Value = ObjctTypeEnum.VAT_INVOICE}
                                                     };

        private DataSetFSO.CONTRACTRow _rowContract; 
        private bool _isNew;
		public bool AllowSave;

        public FormContract()
        {            
            InitializeComponent();

            _isNew = true;

            _rowContract = dataSetFSO1.CONTRACT.NewCONTRACTRow();

            //Задаем даты по умолчанию
            _rowContract.START_DATE = DateTime.Now.Date;
            _rowContract.END_DATE = DateTime.Now.Date;

            dataSetFSO1.CONTRACT.AddCONTRACTRow(_rowContract);           
        }

        public FormContract(DataSetFSO.CONTRACTRow rowContract)
        {
            InitializeComponent();

            _isNew = false;

            contractTableAdapter1.FillByID(dataSetFSO1.CONTRACT, rowContract.ID);            
            _rowContract = dataSetFSO1.CONTRACT.FindByID(rowContract.ID);
           
            this.Text = "Договор " + _rowContract.NUMBER;
        }

        public FormContract(DataSetFSO.CONTRACTRow parentContractRow, bool child)
        {
            InitializeComponent();            

            _isNew = true;

            _rowContract = dataSetFSO1.CONTRACT.NewCONTRACTRow();

            //Задаем даты по умолчанию
            _rowContract.START_DATE = DateTime.Now.Date;
            _rowContract.END_DATE = DateTime.Now.Date;

            dataSetFSO1.CONTRACT.AddCONTRACTRow(_rowContract);

            if (child)
            {
                if (!parentContractRow.IsNSI_ORGANIZATION_IDNull())
                {
                    _rowContract.NSI_ORGANIZATION_ID = parentContractRow.NSI_ORGANIZATION_ID;
                }

                if (!parentContractRow.IsNSI_TYPE_OF_ACTIVITY_IDNull())
                {
                    _rowContract.NSI_TYPE_OF_ACTIVITY_ID = parentContractRow.NSI_TYPE_OF_ACTIVITY_ID;
                }

                _rowContract.PARENT_CONTRACT_ID = parentContractRow.ID;
            }                       
        }

        public void BindConrols()
        {
            //Номер
            radTextBoxNumber.DataBindings.Clear();
            radTextBoxNumber.DataBindings.Add("Text", _rowContract, dataSetFSO1.CONTRACT.NUMBERColumn.ColumnName, true, DataSourceUpdateMode.OnPropertyChanged);

            //Дата начала и дата конца
            radDateTimePickerStartDate.DataBindings.Clear();
            radDateTimePickerStartDate.DataBindings.Add("Value", _rowContract, dataSetFSO1.CONTRACT.START_DATEColumn.ColumnName, true, DataSourceUpdateMode.OnPropertyChanged);

            radDateTimePickerEndDate.DataBindings.Clear();
            radDateTimePickerEndDate.DataBindings.Add("Value", _rowContract, dataSetFSO1.CONTRACT.END_DATEColumn.ColumnName, true, DataSourceUpdateMode.OnPropertyChanged);

            //Вид договора
            radDropDownListTypeDoc.DataBindings.Clear();
            radDropDownListTypeDoc.DataBindings.Add("SelectedValue", _rowContract, dataSetFSO1.CONTRACT.TYPE_DOCColumn.ColumnName, true, DataSourceUpdateMode.OnPropertyChanged);

            //Тип договора
            radDropDownListTypeWork.DataBindings.Clear();
            radDropDownListTypeWork.DataBindings.Add("SelectedValue", _rowContract, dataSetFSO1.CONTRACT.TYPE_WORKColumn.ColumnName, true, DataSourceUpdateMode.OnPropertyChanged);

            //Направление
            radDropDownListNSIRTypeOfActivity.DataBindings.Clear();
            radDropDownListNSIRTypeOfActivity.DataBindings.Add("SelectedValue", _rowContract, dataSetFSO1.CONTRACT.NSI_TYPE_OF_ACTIVITY_IDColumn.ColumnName, true, DataSourceUpdateMode.OnPropertyChanged);

            //Комментарии
            radTextBoxDescription.DataBindings.Clear();
            radTextBoxDescription.DataBindings.Add("Text", _rowContract, dataSetFSO1.CONTRACT.DESCRIPTIONColumn.ColumnName, true, DataSourceUpdateMode.OnPropertyChanged);

            //Заказчик
            if (!_rowContract.IsNSI_ORGANIZATION_IDNull())            {
                
                radLabelOrg.DataBindings.Clear();
                radLabelOrg.DataBindings.Add("Text", _rowContract.NSI_ORGANIZATIONRow, dataSetFSO1.NSI_ORGANIZATION.SHORT_NAMEColumn.ColumnName, false, DataSourceUpdateMode.Never, "<Не указан>");
            }
            else
            {
                radLabelOrg.Text = "<Не указан>";
            }

            //Родительский договор
            if (!_rowContract.IsPARENT_CONTRACT_IDNull())
            {
                radLabelParentContract.DataBindings.Clear();
                radLabelParentContract.DataBindings.Add("Text", _rowContract.CONTRACTRowParent, dataSetFSO1.CONTRACT.NUMBERColumn.ColumnName, false, DataSourceUpdateMode.Never, "<Не указан>");
            }
            else
            {
                radLabelParentContract.Text = "<Не указан>";
            }
        }

        public void InitializeChildGridView()
        {
            radGridViewChildContracts.ReadOnly = true;
            radGridViewChildContracts.EnableGrouping = false;
            radGridViewChildContracts.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            radGridViewChildContracts.DataSource = null;

            GridViewTextBoxColumn colNumber = new GridViewTextBoxColumn(dataSetFSO2.CONTRACT.NUMBERColumn.ColumnName);
            colNumber.HeaderText = "№";

            GridViewDateTimeColumn colStartDate = new GridViewDateTimeColumn(dataSetFSO2.CONTRACT.START_DATEColumn.ColumnName);
            colStartDate.HeaderText = "Дата начала";
            colStartDate.FormatString = "{0:d}";

            GridViewDateTimeColumn colEndDate = new GridViewDateTimeColumn(dataSetFSO2.CONTRACT.END_DATEColumn.ColumnName);
            colEndDate.HeaderText = "Дата окончания";
            colEndDate.FormatString = "{0:d}";

            GridViewTextBoxColumn colId = new GridViewTextBoxColumn(dataSetFSO2.CONTRACT.IDColumn.ColumnName);
            GridViewTextBoxColumn colParentId = new GridViewTextBoxColumn(dataSetFSO2.CONTRACT.PARENT_CONTRACT_IDColumn.ColumnName);

            radGridViewChildContracts.MasterTemplate.Columns.Clear();
            radGridViewChildContracts.MasterTemplate.Columns.Add(colNumber);
            radGridViewChildContracts.MasterTemplate.Columns.Add(colStartDate);
            radGridViewChildContracts.MasterTemplate.Columns.Add(colEndDate);
            radGridViewChildContracts.MasterTemplate.Columns.Add(colId);
            radGridViewChildContracts.MasterTemplate.Columns.Add(colParentId);

            radGridViewChildContracts.Columns[dataSetFSO2.CONTRACT.IDColumn.ColumnName].IsVisible = false;
            radGridViewChildContracts.Columns[dataSetFSO2.CONTRACT.PARENT_CONTRACT_IDColumn.ColumnName].IsVisible = false;

            //Рекурсивно заполняем всех потомков контракта
            
            contractTableAdapter1.FillAllChildByID(dataSetFSO2.CONTRACT, _rowContract.ID);
            

            radGridViewChildContracts.DataSource = dataSetFSO2.CONTRACT;

            //Создание связи для реализации иерархии
            //GridViewRelation relation = new GridViewRelation(radGridViewChildContracts.MasterTemplate, radGridViewChildContracts.MasterTemplate);

            //relation.ParentColumnNames.Add(dataSetFSO2.CONTRACT.IDColumn.ColumnName);
            //relation.ChildColumnNames.Add(dataSetFSO2.CONTRACT.PARENT_CONTRACT_IDColumn.ColumnName);
            //relation.RelationName = "CONTRACT_CONTRACT";
            radGridViewChildContracts.Relations.Clear();
            radGridViewChildContracts.Relations.AddSelfReference(radGridViewChildContracts.MasterTemplate, dataSetFSO2.CONTRACT.IDColumn.ColumnName, dataSetFSO2.CONTRACT.PARENT_CONTRACT_IDColumn.ColumnName);

        }
             

        #region IntefaceObjectForm Members

        public int Save()
        {
            int nRowsUpdatedCount = -1;

            if (_rowContract.IsNUMBERNull())
            {
                MessageBox.Show(this, "Не заполнено обязательное поле \"№\".\nИзменения не будут сохранены", "Обязательное поле", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                nRowsUpdatedCount = contractTableAdapter1.Update(_rowContract); ;
                _isNew = false; ;
                radButtonCreateChildContract.Enabled = true;
                this.RefreshForm();
            }            
            return nRowsUpdatedCount;
        }

        public int RefreshForm()
        {
            int result=0;

            //Обновляем Направление
            nsI_TYPE_OF_ACTIVITYTableAdapter1.Fill(dataSetFSO1.NSI_TYPE_OF_ACTIVITY);
            radDropDownListNSIRTypeOfActivity.Items.Clear();
            foreach (DataSetFSO.NSI_TYPE_OF_ACTIVITYRow row in dataSetFSO1.NSI_TYPE_OF_ACTIVITY.Rows)
            {
                radDropDownListNSIRTypeOfActivity.Items.Add(new RadListDataItem() { Text = row.NAME, Value = row.ID });
            }
                        
            //Обновляем список связанных вх и исх счетов, вх платежей, протоколов и всех потомков
            if (!_isNew)
            {
                vieW_SEARCH_INVOICE_INTableAdapter1.FillByContractId(dataSetFSO1.VIEW_SEARCH_INVOICE_IN, _rowContract.ID);        
                
                InitializeChildGridView();


            }

            this.BindConrols();

            return result;
        }               

        public string FormName
        {
            get
            {
                string returnString = "Contract_";

                if (_isNew)
                {
                    returnString = returnString + DateTime.Now;
                }
                else
                {
                    returnString = returnString + _rowContract.ID;
                }
                return returnString;
            }
        }

        #endregion

        #region InterfaceObjDeleteableForm

        public int Delete()
        {
            int nRowsDeletedCount = -1;

            try
            {
                //_rowContract.SetPIDNull();
                _rowContract.Delete();
                nRowsDeletedCount += contractTableAdapter1.Update(_rowContract);
                this.Close();
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                _rowContract.RejectChanges();
                MessageBox.Show(e.Message);
                MessageBox.Show(this, "Невозможно удалить договор!", "Ошибка удаления", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
            return nRowsDeletedCount;
        }

        #endregion
        
        #region Events

        private void FormContract_Load(object sender, EventArgs e)
        {
            //Заполняем выпадающий список связанных элементов
            foreach (Telerik.WinControls.UI.RadListDataItem item in _refObjects)
            {
                radDropDownListRefObj.Items.Add(item);
            }

            if (_isNew)
            {
                radButtonCreateChildContract.Enabled = false;
            }

            //Заполняем таблицу организаций
            if (!_rowContract.IsNSI_ORGANIZATION_IDNull())
            {
                nsI_ORGANIZATIONTableAdapter1.FillById(dataSetFSO1.NSI_ORGANIZATION, _rowContract.NSI_ORGANIZATION_ID);
            }

            //Добавляем родительский договор
            if (!_rowContract.IsPARENT_CONTRACT_IDNull())
            {
                contractTableAdapter1.ClearBeforeFill = false;
                contractTableAdapter1.FillByID(dataSetFSO1.CONTRACT, _rowContract.PARENT_CONTRACT_ID);
                contractTableAdapter1.ClearBeforeFill = true;
            }

            //Заполняем список связанных элементов
            if (!_isNew)
            {
                vieW_SEARCH_INVOICE_INTableAdapter1.FillByContractId(dataSetFSO1.VIEW_SEARCH_INVOICE_IN, _rowContract.ID);
            }

            //Настройка таблицы входящих счетов
            userControlSearchInvoiceIn1.OpenOnDoubleClick = true;
            userControlSearchInvoiceIn1.EnableFiltering = false;
            userControlSearchInvoiceIn1.OwnerDataSet = dataSetFSO1;

            //Заполняем выпадающий список "Направление"
            nsI_TYPE_OF_ACTIVITYTableAdapter1.Fill(dataSetFSO1.NSI_TYPE_OF_ACTIVITY);
            radDropDownListNSIRTypeOfActivity.Items.Clear();
            foreach (DataSetFSO.NSI_TYPE_OF_ACTIVITYRow row in dataSetFSO1.NSI_TYPE_OF_ACTIVITY.Rows)
            {
                radDropDownListNSIRTypeOfActivity.Items.Add(new RadListDataItem() { Text = row.NAME, Value = row.ID });
            }
            
            //Инициаизация выпадающих списков
            radDropDownListTypeDoc.Items.Add(new RadListDataItem() { Text = "Договор", Value = "Договор" });
            radDropDownListTypeDoc.Items.Add(new RadListDataItem() { Text = "Гарантийное письмо", Value = "Гарантийное письмо" });

            radDropDownListTypeWork.Items.Add(new RadListDataItem() { Text = "Поставка", Value = "Поставка" });
            radDropDownListTypeWork.Items.Add(new RadListDataItem() { Text = "ОКР", Value = "ОКР" });
            
            //Таблица доп. соглашений
            InitializeChildGridView();

            this.BindConrols();
        }       

        private void FormContract_FormClosing(object sender, FormClosingEventArgs e)
        {
			if (!AllowSave)
				return;
            if (_rowContract.RowState == DataRowState.Added || _rowContract.RowState == DataRowState.Modified)
            {
                DialogResult result = MessageBox.Show(this, "Были внесены изменения. Сохранить?", "Сохранить изменения?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    int SaveResult = this.Save();

                    if (SaveResult == -1)
                    {
                        e.Cancel = true;
                    }
                }
                else if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
                else
                {
                    _rowContract.RejectChanges();
                }

            }
        }

        private void radLabelOrg_DoubleClick(object sender, EventArgs e)
        {
            if (_rowContract.IsNSI_ORGANIZATION_IDNull())
            {                
                //DialogFormSelectOrganization dialogSelectedOrganization = new DialogFormSelectOrganization();
                DialogFormSelectObject dialogSelectedOrganization = new DialogFormSelectObject(ObjctTypeEnum.ORGANIZATION);
                if (dialogSelectedOrganization.ShowDialog() == DialogResult.OK)
                {
                    DataSetFSO.NSI_ORGANIZATIONRow orgRow = (DataSetFSO.NSI_ORGANIZATIONRow)dialogSelectedOrganization.SelectedRow;

                    if (orgRow != null)
                    {
                        nsI_ORGANIZATIONTableAdapter1.FillById(dataSetFSO1.NSI_ORGANIZATION, orgRow.ID);
                        _rowContract.NSI_ORGANIZATIONRow = dataSetFSO1.NSI_ORGANIZATION.FindByID(orgRow.ID);
                    }

                    if (_rowContract.NSI_ORGANIZATIONRow != null)
                    {
                        radLabelOrg.DataBindings.Clear();
                        radLabelOrg.DataBindings.Add("Text", _rowContract.NSI_ORGANIZATIONRow, dataSetFSO1.NSI_ORGANIZATION.SHORT_NAMEColumn.ColumnName, true, DataSourceUpdateMode.Never);
                    }

                }
            }
            else
            {
                FormNSIOrganization formOrg = new FormNSIOrganization(_rowContract.NSI_ORGANIZATIONRow);
                if (!FormHelper.HasOpenedForm(formOrg.FormName))
                {
                    formOrg.MdiParent = FormHelper.MainForm;
                    formOrg.Show();
                    formOrg.Select();
                }
            }
        }

        private void radButtonDeleteOrg_Click(object sender, EventArgs e)
        {
            _rowContract.SetNSI_ORGANIZATION_IDNull();
             this.BindConrols();
        }              

        private void radButtonDeleteParentContract_Click(object sender, EventArgs e)
        {
            _rowContract.SetPARENT_CONTRACT_IDNull();
            this.BindConrols();
        }        

        private void radLabelParentContract_DoubleClick(object sender, EventArgs e)
        {
            if (_rowContract.IsPARENT_CONTRACT_IDNull())
            {
                //DialogFormSelectContract dialogSelectedContract = new DialogFormSelectContract();
                DialogFormSelectObject dialogSelectedContract = new DialogFormSelectObject(ObjctTypeEnum.CONTRACT);
                if (dialogSelectedContract.ShowDialog() == DialogResult.OK)
                {
                    DataSetFSO.CONTRACTRow contractRow = (DataSetFSO.CONTRACTRow)dialogSelectedContract.SelectedRow;
                    if (contractRow != null)
                    {
                        contractTableAdapter1.ClearBeforeFill = false;
                        contractTableAdapter1.FillByID(dataSetFSO1.CONTRACT, contractRow.ID);
                        contractTableAdapter1.ClearBeforeFill = true;
                        _rowContract.CONTRACTRowParent = dataSetFSO1.CONTRACT.FindByID(contractRow.ID);
                    }
                    if (_rowContract.CONTRACTRowParent != null)
                    {
                        radLabelParentContract.DataBindings.Clear();
                        radLabelParentContract.DataBindings.Add("Text", _rowContract.CONTRACTRowParent, dataSetFSO1.CONTRACT.NUMBERColumn.ColumnName, true, DataSourceUpdateMode.Never);
                    }
                }
            }
            else
            {
                FormContract formContract = new FormContract(_rowContract.CONTRACTRowParent);
                if (!FormHelper.HasOpenedForm(formContract.FormName))
                {
                    formContract.MdiParent = FormHelper.MainForm;
                    formContract.Show();
                    formContract.Select();
                }
            }
        }      

        private void radGridViewChildContracts_CellDoubleClick(object sender, GridViewCellEventArgs e)
        {
            DataRowView drvSelectedItem = (DataRowView)e.Row.DataBoundItem;
            if (drvSelectedItem != null)
            {
                DataSetFSO.CONTRACTRow oSelect = (DataSetFSO.CONTRACTRow)drvSelectedItem.Row;
                FormContract formContract = new FormContract(oSelect);
                if (!FormHelper.HasOpenedForm(formContract.FormName))
                {
                    formContract.MdiParent = FormHelper.MainForm;
                    formContract.Show();
                    formContract.Select();
                }                
            }
        }

        private void radButtonCreateChildContract_Click(object sender, EventArgs e)
        {
            FormContract formContract = new FormContract(_rowContract, true);
            if (!FormHelper.HasOpenedForm(formContract.FormName))
            {
                formContract.MdiParent = FormHelper.MainForm;
                formContract.Show();
                formContract.Select();
            }                
        }        

        private void radDropDownListRefObj_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            if (!_isNew)
            {
                panelRefObj.Controls.Clear();

                if (radDropDownListRefObj.SelectedItem != null)
                {
                    //Очищаем все таблицы
                    dataSetFSO1.CALENDAR_PLAN.Clear();
                    dataSetFSO1.COST_PROTOCOL.Clear();
                    dataSetFSO1.INVOICE_OUT.Clear();
                    dataSetFSO1.PAYMENT_IN.Clear();
                    dataSetFSO1.DIRECT.Clear();
                    dataSetFSO1.GUILD_BILL.Clear();
                    dataSetFSO1.VAT_INVOICE.Clear();

                    switch ((ObjctTypeEnum)radDropDownListRefObj.SelectedItem.Value)
                    {
                        case ObjctTypeEnum.CALENDAR_PLAN:
                            panelRefObj.Controls.Add(new UserControlSearchCalendarPlan() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true, OwnerDataSet = dataSetFSO1 });
                            View_SEARCH_CALENDAR_PLANTableAdapter taCaledarPlan = new View_SEARCH_CALENDAR_PLANTableAdapter();
                            taCaledarPlan.FillByContractId(dataSetFSO1.View_SEARCH_CALENDAR_PLAN, _rowContract.ID);
                            break;
                        case ObjctTypeEnum.COST_PROTOCOL:
                            panelRefObj.Controls.Add(new UserControlSeachCostProtocol() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true, OwnerDataSet = dataSetFSO1 });
                            VIEW_SEARCH_COST_PROTOCOLTableAdapter taCostPr = new VIEW_SEARCH_COST_PROTOCOLTableAdapter();
                            taCostPr.FillByPid(dataSetFSO1.VIEW_SEARCH_COST_PROTOCOL, _rowContract.PID);
                            break;
                        case ObjctTypeEnum.INVOICE_OUT:
                            panelRefObj.Controls.Add(new UserControlSearchInvoiceOut() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true, OwnerDataSet = dataSetFSO1 });
                            VIEW_SEARCH_INVOICE_OUTTableAdapter taInvOut = new VIEW_SEARCH_INVOICE_OUTTableAdapter();
                            taInvOut.FillByPID(dataSetFSO1.VIEW_SEARCH_INVOICE_OUT, _rowContract.PID);
                            break;
                        case ObjctTypeEnum.PAYMENT_IN:
                            panelRefObj.Controls.Add(new UserControlSearchPaymentIn() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true, OwnerDataSet = dataSetFSO1 });
                            VIEW_SEARCH_PAYMENT_INTableAdapter taPayIn = new VIEW_SEARCH_PAYMENT_INTableAdapter();
                            taPayIn.FillByPID(dataSetFSO1.VIEW_SEARCH_PAYMENT_IN, _rowContract.PID);
                            break;
                        case ObjctTypeEnum.DIRECT:
                            panelRefObj.Controls.Add(new UserControlSearchDirect() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true, OwnerDataSet = dataSetFSO1 });
                            VIEW_SEARCH_DIRECTTableAdapter taDirect = new VIEW_SEARCH_DIRECTTableAdapter();
                            taDirect.FillByPID(dataSetFSO1.VIEW_SEARCH_DIRECT, _rowContract.PID);
                            break;
                        case ObjctTypeEnum.GUILD_BILL:
                            panelRefObj.Controls.Add(new UserControlSearchGuildBill() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true, OwnerDataSet = dataSetFSO1 });
                            VIEW_SEARCH_GUILD_BILLTableAdapter taGuildBill = new VIEW_SEARCH_GUILD_BILLTableAdapter();
                            taGuildBill.FillByPID(dataSetFSO1.VIEW_SEARCH_GUILD_BILL, _rowContract.PID);
                            break;   
                        case ObjctTypeEnum.VAT_INVOICE:
                            panelRefObj.Controls.Add(new UserControlSearchVatInvoice() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true, OwnerDataSet = dataSetFSO1 });
                            VIEWS_SEARCH_VAT_INVOICETableAdapter taVatInv = new VIEWS_SEARCH_VAT_INVOICETableAdapter();
                            taVatInv.FillByPID(dataSetFSO1.VIEWS_SEARCH_VAT_INVOICE, _rowContract.PID);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        #endregion
    }
}

